package com.hundsun.yr.universal.p2p.ui.fragment;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.icu.lang.UScript;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.widget.NestedScrollView;
import android.support.v4.widget.SwipeRefreshLayout;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.gyf.barlibrary.ImmersionBar;
import com.hundsun.mobile.zwgt.R;
import com.hundsun.yr.universal.library.Utils.HeaderMap;
import com.hundsun.yr.universal.library.adapter.HolderAdapter;
import com.hundsun.yr.universal.library.adapter.ViewCreatorHelper;
import com.hundsun.yr.universal.library.adapter.ViewCreatorHelper.UpdateItem;
import com.hundsun.yr.universal.library.base.BaseWebActivity;
import com.hundsun.yr.universal.library.data.HSSharedPreferences;
import com.hundsun.yr.universal.library.eventbus.EventCenter;
import com.hundsun.yr.universal.library.netstatus.NetUtils;
import com.hundsun.yr.universal.library.receiver.ScreenReceiver;
import com.hundsun.yr.universal.library.receiver.ScreenReceiver.ScreenListener;
import com.hundsun.yr.universal.library.utils.HsDateUtils;
import com.hundsun.yr.universal.library.utils.MathUtils;
import com.hundsun.yr.universal.library.view.hsdialog.HSDialog;
import com.hundsun.yr.universal.library.view.hsdialog.HSDialog.HSDialogOnItemClickListener;
import com.hundsun.yr.universal.library.widget.HSButton;
import com.hundsun.yr.universal.library.widget.HSTabLayout;
import com.hundsun.yr.universal.library.widget.HSTabLayout.OnTabChangeListener;
import com.hundsun.yr.universal.library.widget.NoScrollViewPager;
import com.hundsun.yr.universal.p2p.HsApplication;
import com.hundsun.yr.universal.p2p.bean.AdSlideBeen;
import com.hundsun.yr.universal.p2p.bean.AssetInfoBean;
import com.hundsun.yr.universal.p2p.bean.AutoBidInfoBean;
import com.hundsun.yr.universal.p2p.bean.BankAccountBeen;
import com.hundsun.yr.universal.p2p.bean.MixrepayPlanBean;
import com.hundsun.yr.universal.p2p.bean.UserAccount;
import com.hundsun.yr.universal.p2p.bean.UserInfo;
import com.hundsun.yr.universal.p2p.config.Config;
import com.hundsun.yr.universal.p2p.config.Constants;
import com.hundsun.yr.universal.p2p.config.Extras;
import com.hundsun.yr.universal.p2p.config.TaskConstants;
import com.hundsun.yr.universal.p2p.interactor.impl.MineInteractorImpl;
import com.hundsun.yr.universal.p2p.presenter.base.RequestPresenter;
import com.hundsun.yr.universal.p2p.presenter.impl.ItemViewPresenterImpl;
import com.hundsun.yr.universal.p2p.ui.activity.AutoBidAuthActivity;
import com.hundsun.yr.universal.p2p.ui.activity.InviteFrientsActivity;
import com.hundsun.yr.universal.p2p.ui.activity.LendActivity;
import com.hundsun.yr.universal.p2p.ui.activity.LoginActivity;
import com.hundsun.yr.universal.p2p.ui.activity.MainActivity;
import com.hundsun.yr.universal.p2p.ui.activity.ManagementActivity;
import com.hundsun.yr.universal.p2p.ui.activity.MineInvestActivity;
import com.hundsun.yr.universal.p2p.ui.activity.MineLoanActivity;
import com.hundsun.yr.universal.p2p.ui.activity.MineMoreActivity;
import com.hundsun.yr.universal.p2p.ui.activity.MineSettingActivity;
import com.hundsun.yr.universal.p2p.ui.activity.OpenAccountBankActivity;
import com.hundsun.yr.universal.p2p.ui.activity.RechangeNewActivity;
import com.hundsun.yr.universal.p2p.ui.activity.WebActivity;
import com.hundsun.yr.universal.p2p.ui.activity.WebOpenAccountActivity;
import com.hundsun.yr.universal.p2p.ui.activity.WebRiskActivity;
import com.hundsun.yr.universal.p2p.ui.activity.WithDrawActivity;
import com.hundsun.yr.universal.p2p.ui.activity.base.BaseFragment;
import com.hundsun.yr.universal.p2p.utils.BaseRequestTool2;
import com.hundsun.yr.universal.p2p.utils.CommTool;
import com.hundsun.yr.universal.p2p.view.base.BaseItemView;
import com.qiyukf.unicorn.api.ConsultSource;
import com.qiyukf.unicorn.api.ProductDetail;
import com.qiyukf.unicorn.api.Unicorn;
import com.qiyukf.unicorn.api.YSFUserInfo;
import com.qiyukf.unicorn.utils.Utils;
import com.umeng.analytics.MobclickAgent;

import org.json.JSONObject;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.TimeZone;


/**
 * @version V1.0
 * @Title: MineFragment.java
 * @Description: 个人中心
 * @date 2016-4-5 下午4:32:34
 * @author:hejun.shen
 * @email:shenhj15971@hundsun.com
 * @replace author:
 * @replace date:
 */
public class MineFragment extends BaseFragment implements BaseItemView, OnItemClickListener
        , UpdateItem<HashMap<String, Object>>, OnClickListener,
        HSDialogOnItemClickListener,
        SwipeRefreshLayout.OnRefreshListener {
    /**
     * 数据接口
     **/
    private RequestPresenter mPresenter;
//    private GridView gv_mine;
    /**
     * 适配器
     **/
    private HolderAdapter<HashMap<String, Object>> mAdapter;
    /**
     * 交易记录
     **/
    private TextView tv_time_and_num = null;
    /**
     * 资产总额文字
     **/
//    private TextView tv_totalassets_txt = null;
    /**
     * 总资产
     **/
    private TextView tv_assets = null;
    /**
     * 登录点击区域
     **/
//    private LinearLayout linear_login = null;
    /**
     * 设置按钮
     **/
    private ImageView iv_setting = null;
    /**
     * 累計收益
     **/
//    private TextView tv_income = null;
    /**
     * 可用余额
     **/
    private TextView tv_balance = null;
    /**
     * 刷新功能
     **/
//    private LinearLayout linear_refresh = null;
    /**
     * 绑卡弹窗
     **/
    private HSDialog dialog_bindcard = null;
    /**
     * 开户界面
     **/
    private HSDialog dialog_bindname = null;
    /**
     * 我的资产返回值（用来判断是否需要刷新）
     **/
    private String assetResult;
    /**
     * 账户总资产对象
     **/
    private UserAccount account;
    /**
     * 界面显示在当前标签页
     **/
    private boolean isCurrentTab;
    /**
     * 荧屏广播
     **/
    private ScreenReceiver screenReceiver;
    /**
     * 银行卡布局
     **/
    private LinearLayout linear_bankcard = null;
    /**
     * 江西银行虚拟银行卡号
     **/
    private TextView tv_cardnum = null;
    private String zwgt_data;
    private NestedScrollView scrollView;

    /**
     * 用户银行卡等情况，各种信息，网络请求成功才能有返回值
     */
    private BankAccountBeen bankAccountBeen = null;

    private HSSharedPreferences mConfigSP = null;
    private AssetInfoBean assetInfoBean;

    private MineInteractorImpl mineInteractor = null;

    /**
     * 转入
     */
    private ImageView btn_to_in = null;

    /**
     * 转出
     */
    private ImageView btn_to_out = null;

    /**
     * 风险评估
     */
    private LinearLayout ll_risk_estimate = null;

    /**
     * 我的投资
     */
    private LinearLayout ll_my_invest = null;

    /**
     * 我的借款
     */
    private LinearLayout ll_my_loan = null;

    /**
     * 我的资金流水
     */
    private LinearLayout ll_my_invest_stream = null;

    /**
     * 联系客服
     */
    private LinearLayout ll_contact_customer_service = null;

    /**
     * 帮助中心
     */
    private LinearLayout ll_help_center = null;

    /**
     * 自动投标，根据不同的用户对自动投标进行显示和隐藏
     */
//    private LinearLayout ll_automatic_bid = null;


    /**
     * 优惠券
     */
    private LinearLayout ll_coupon = null;

    /**
     * 银行卡
     */
    private LinearLayout ll_my_bank_card = null;

    /**
     * 签到
     */
    private LinearLayout ll_invite_frients = null;

    /**
     * 新闻公告
     */
    private LinearLayout ll_news_notice = null;

    /**
     * 授权管理
     */
    private LinearLayout ll_authorization = null;

    /**
     * 小眼睛显示隐藏数字
     */
    private ImageView im_eye = null;

    /**
     * 是否显示数字
     */
    private boolean ISOPEN = true;

    /**
     * 刷新
     */
    private SwipeRefreshLayout mine_hsSwipeRefreshLayou = null;

    /**
     * 弹出pop确认开户|确认理财
     */
    private PopupWindow popWindow;

    /**
     * 头像Logo
     */
    private ImageView iv_user_logo = null;

    /**
     * 在投昨日收益
     */
    private TextView tv_ear_from_yes_investment = null;

    /**
     * 累计收益
     */
    private TextView tv_cumulative_investment = null;
    private boolean ISNEWREGISTER = false;

    private TextView tv_risk_estimate = null;

    private HSDialog paypwdDialog;

    /**
     * 实名认证弹窗
     */
    private HSDialog SignNameDialog;
    /**
     * 设置交易密码
     */
    private HSDialog payCodeDialog;

    /**
     * 绑卡dialog
     */
    private HSDialog bindCardDialog;

    /**
     * 缴费授权
     */
    private HSDialog payDialog;

    @Override
    protected void onFirstUserVisible() {
        mConfigSP = new HSSharedPreferences(mContext, Config.SPPath.file_configInfo);
        mPresenter = new ItemViewPresenterImpl(mContext, this, new MineInteractorImpl());
        loadingData();
        refreshUI();
    }

    private void loadingData() {
        zwgt_data = BaseRequestTool2.getFormatedDateString();
        mPresenter.loadingData(TaskConstants.TASK_BANK_ACCOUNT, getString(R.string.root_url_test) + getString(R.string.api_user_test) +
                TaskConstants.TASK_BANK_ACCOUNT, Constants.EVENT_BEGIN, BaseRequestTool2.getHearder(mContext, TaskConstants.TASK_GET, getString(R.string.api_user_test)
                + TaskConstants.TASK_BANK_ACCOUNT, sharedPreferences.getShareProf(UserInfo.USER_NO), sharedPreferences.getShareProf(UserInfo.TOKENID), zwgt_data), true);

        zwgt_data = BaseRequestTool2.getFormatedDateString();
        mPresenter.loadingData(TaskConstants.TASK_ASSETINFO, getString(R.string.root_url_test) + getString(R.string.api_user_test) +
                TaskConstants.TASK_ASSETINFO, Constants.EVENT_BEGIN, BaseRequestTool2.getHearder(mContext, TaskConstants.TASK_GET, getString(R.string.api_user_test)
                + TaskConstants.TASK_ASSETINFO, sharedPreferences.getShareProf(UserInfo.USER_NO), sharedPreferences.getShareProf(UserInfo.TOKENID), zwgt_data), false);
    }

    @Override
    public void onAttach(Activity activity) {
        MainActivity ac = (MainActivity) activity;
        HSTabLayout tabLayout = ac.getTabLayout();
        if (tabLayout != null) {
            tabLayout.setOnTabChangeListener(new OnTabChangeListener() {
                @Override
                public void onTabSelected(int position) {
                    isCurrentTab = position == 3;
                }
            });
        }
        super.onAttach(activity);
    }


    @Override
    protected void onUserVisible() {
        refreshUI();
        MobclickAgent.onPageStart("MineFragment");
    }

    @Override
    protected void onUserInvisible() {
        MobclickAgent.onPageEnd("MineFragment");
    }

    @Override
    protected View getLoadingTargetView() {
        return null;
    }

    @Override
    protected void initViewsAndEvents() {
        tv_time_and_num = findView(R.id.tv_time_and_num);
        tv_assets = findView(R.id.tv_assets);
        iv_setting = findView(R.id.iv_setting);
        iv_setting.setOnClickListener(this);
        tv_balance = findView(R.id.tv_balance);
        linear_bankcard = findView(R.id.linear_bankcard);
        scrollView = findView(R.id.scrollView);
        btn_to_in = findView(R.id.btn_to_in);
        btn_to_out = findView(R.id.btn_to_out);
        ll_my_invest = findView(R.id.ll_my_invest);
        ll_risk_estimate = findView(R.id.ll_risk_estimate);
        ll_my_loan = findView(R.id.ll_my_loan);
        ll_my_invest_stream = findView(R.id.ll_my_invest_stream);
        ll_contact_customer_service = findView(R.id.ll_contact_customer_service);
        ll_help_center = findView(R.id.ll_help_center);
//        ll_automatic_bid = findView(R.id.ll_automatic_bid);
        ll_coupon = findView(R.id.ll_coupon);
        ll_my_bank_card = findView(R.id.ll_my_bank_card);
        ll_invite_frients = findView(R.id.ll_invite_frients);
        ll_news_notice = findView(R.id.ll_news_notice);
        im_eye = findView(R.id.im_eye);
        iv_user_logo = findView(R.id.iv_user_logo);
        mine_hsSwipeRefreshLayou = findView(R.id.mine_hsSwipeRefreshLayou);
        tv_ear_from_yes_investment = findView(R.id.tv_ear_from_yes_investment);
        tv_cumulative_investment = findView(R.id.tv_cumulative_investment);
        tv_risk_estimate = findView(R.id.tv_risk_estimate);
        ll_authorization = findView(R.id.ll_authorization);

        mine_hsSwipeRefreshLayou.setOnRefreshListener(this);

        //点击的监听事件
        btn_to_in.setOnClickListener(this);
        btn_to_out.setOnClickListener(this);
        ll_my_invest.setOnClickListener(this);
        ll_risk_estimate.setOnClickListener(this);
        ll_my_loan.setOnClickListener(this);
        ll_my_invest_stream.setOnClickListener(this);
        ll_contact_customer_service.setOnClickListener(this);
        ll_help_center.setOnClickListener(this);
//        ll_automatic_bid.setOnClickListener(this);
        ll_coupon.setOnClickListener(this);
        ll_my_bank_card.setOnClickListener(this);
        ll_invite_frients.setOnClickListener(this);
        ll_news_notice.setOnClickListener(this);
        im_eye.setOnClickListener(this);
        tv_time_and_num.setOnClickListener(this);
        iv_user_logo.setOnClickListener(this);
        tv_assets.setOnClickListener(this);
        ll_authorization.setOnClickListener(this);
        if (ImmersionBar.isSupportStatusBarDarkFont()) { //判断当前设备支不支持状态栏字体变色
            //处理状态栏字体为黑色l
            ImmersionBar.with(MineFragment.this).titleBar(R.id.rl_mine_title).statusBarDarkFont(true).flymeOSStatusBarFontColor(R.color.black).init();
        } else {
            //处理状态栏有透明度
            ImmersionBar.with(MineFragment.this).titleBar(R.id.rl_mine_title).statusBarDarkFont(true).transparentStatusBar().init();
        }

        tv_cardnum = findView(R.id.tv_cardnum);
        if (mPresenter == null) {
            mineInteractor = new MineInteractorImpl();
            mPresenter = new ItemViewPresenterImpl(mContext, this, mineInteractor);
        }
        //初始化界面
        mPresenter.initialized();
        screenReceiver = new ScreenReceiver();
        screenReceiver.registerScreenReceiver(mContext, new ScreenListener() {

            @Override
            public void screenOn() {
            }

            @Override
            public void screenOff() {
                HsApplication.isSrcreenOn = true;
            }
        });
    }

    @Override
    public void onDestroy() {
        //注销荧屏广播
        screenReceiver.unRegisterScreenReceiver(mContext);
        super.onDestroy();
    }

    @Override
    protected int getContentViewLayoutID() {
        return R.layout.frag_mine;
    }

    // TODO: 2017/5/22 根据eventBus接受传递过来的消息
    @Override
    protected void onEveComming(@SuppressWarnings("rawtypes") EventCenter eventCenter) {
        if (eventCenter.getEventCode() == Constants.EVENT_REFRESH_DATA) {
            loadingData();
            refreshUI();
        } else if (eventCenter.getEventCode() == Extras.REGISTER_SUCCESS) {
            //注册成功，提示开户
            showPopup(iv_user_logo, true);
        } else if (eventCenter.getEventCode() == Extras.OPEN_ACCOUNT_SUCCESS && ISNEWREGISTER) {
            //开户成功，提示投资
            popWindow.dismiss();
            showPopup(iv_user_logo, false);
        }
    }

    @Override
    protected boolean isBindEventBusHere() {
        // TODO Auto-generated method stub
        return true;
    }


    /**
     * 刷新状态，根据是否登陆
     */
    public void refreshUI() {
        String currentTimeMillis = System.currentTimeMillis() + "";
        if (MathUtils.compare(HsDateUtils.timeformat(HsDateUtils.farmat_time_2, currentTimeMillis).substring(0, HsDateUtils.timeformat(HsDateUtils.farmat_time_2, currentTimeMillis).indexOf(":")), "12") <= 0) {
            tv_time_and_num.setText(getString(R.string.good_morning, CommTool.encodPhone(sharedPreferences.getShareProf(UserInfo.MOBILE))));
        } else {
            tv_time_and_num.setText(getString(R.string.good_afternoon, CommTool.encodPhone(sharedPreferences.getShareProf(UserInfo.MOBILE))));
        }

        /**
         * 0	未进行风险评估
         1	不通过
         10	保守型
         20	稳健型
         30	平衡型
         40	成长型
         50	进取型/激进型
         */
        String leverStatu = "";
        switch (sharedPreferences.getShareProf(UserInfo.USERLEVEL)) {
            case "10":
                leverStatu = getString(R.string.level10);
                break;
            case "20":
                leverStatu = getString(R.string.level20);
                break;
            case "30":
                leverStatu = getString(R.string.level30);
                break;
            case "40":
                leverStatu = getString(R.string.level40);
                break;
            case "50":
                leverStatu = getString(R.string.level50);
                break;
            case "60":
                leverStatu = getString(R.string.level60);
                break;
            default:
                leverStatu = getString(R.string.level0);
                break;
        }
        tv_risk_estimate.setText(leverStatu);

    }


    @Override
    public void refreshItem(View view, int position, HashMap<String, Object> map) {
        LinearLayout linear_item = findView(view, R.id.linear_item);
        linear_item.getLayoutParams().height = mScreenWidth * 200 / (4 * 187);
        ImageView iv_logo = findView(view, R.id.iv_logo);
        iv_logo.setImageResource((Integer) map.get("item_icon"));
        TextView tv_lable = findView(view, R.id.tv_lable);
        if (TextUtils.isEmpty((String) map.get("item_name"))) {
            tv_lable.setVisibility(View.GONE);
        } else {
            tv_lable.setText((String) map.get("item_name"));
        }
    }


    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

    }

    private void showProgressToDismiss() {
        showProgress("");
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                closeProgress();
            }
        }, 2000);
    }


    @Override
    public void onClick(View v) {
        if (!NetUtils.isNetworkConnected(mContext)) {
            showProgressToDismiss();
            return;
        }

        if (isFastDoubleClick()) {
            return;
        }

        //如果没有登陆所有的点击都是登陆按钮
        if (!sharedPreferences.getBoolean(UserInfo.ISLOGIN)) {
            readyGo(LoginActivity.class);
            return;
        }

        switch (v.getId()) {

            case R.id.iv_setting://更多
                readyGo(MineMoreActivity.class);
                break;

            case R.id.btn_to_in://转入
                if (mConfigSP.contains(mContext, UserInfo.BANK_ACCOUNT_INTERFACE_SUCCESS) && !mConfigSP.getBoolean(UserInfo.BANK_ACCOUNT_INTERFACE_SUCCESS)) {
                    showProgressToDismiss();
                    return;
                }

                if(TextUtils.equals(sharedPreferences.getShareProf(UserInfo.IF_ACCOUNT),"YES")){
                    if(TextUtils.equals(sharedPreferences.getShareProf(UserInfo.IF_PAYPWD),"YES")){
                        if(TextUtils.equals(sharedPreferences.getShareProf(UserInfo.IF_BINDCARD),"YES")){
                            Bundle bundle = new Bundle();
                            bundle.putBoolean("MINERECHARGE", true);
                            readyGo(RechangeNewActivity.class, bundle);
                        }else {
                            dialog_bindname = new HSDialog(getString(R.string.tips), "您尚未绑定银行卡，请先绑卡", "取消",
                                    "去绑卡", mContext, this).setCancelable(false);
                            dialog_bindname.show();
                        }
                    }else {
                        dialog_bindname = new HSDialog(getString(R.string.tips), "您尚未设置交易密码，请前往设置", "取消",
                                "去设置", mContext, this).setCancelable(false);
                        dialog_bindname.show();
                    }
                }else {
                    dialog_bindname = new HSDialog(getString(R.string.tips), "您尚未完成实名认证，请前往实名", "取消",
                            "去实名", mContext, this).setCancelable(false);
                    dialog_bindname.show();
                }
                break;
            case R.id.btn_to_out://转出
                if (mConfigSP.contains(mContext, UserInfo.BANK_ACCOUNT_INTERFACE_SUCCESS) && !mConfigSP.getBoolean(UserInfo.BANK_ACCOUNT_INTERFACE_SUCCESS)) {
                    showProgressToDismiss();
                    return;
                }
                /**
                 * 提现判断
                 */
                String zwgt_data = BaseRequestTool2.getFormatedDateString();
                JSONObject map = new JSONObject();
                JSONObject jsonParams = CommTool.getJSONParams(map, sharedPreferences.getShareProf(UserInfo.TOKENID).substring(0, 24), zwgt_data);
                mPresenter.loadingData(TaskConstants.TASK_NEW_TRADE, getString(R.string.root_url_test) + getString(R.string.api_trade_isauth),
                        Constants.EVENT_DATA, jsonParams, BaseRequestTool2.getHearder(mContext, TaskConstants.TASK_POST, getString(R.string.api_trade_isauth),
                                sharedPreferences.getShareProf(UserInfo.USER_NO),
                                sharedPreferences.getShareProf(UserInfo.TOKENID), zwgt_data), true);

                break;
            case R.id.ll_risk_estimate://风险评估
                if (!NetUtils.isNetworkConnected(mContext)) {
                    showProgressToDismiss();
                    return;
                }

                //level  0 和 1可以点击进入风险评估页面的
                if (sharedPreferences.contains(mContext, UserInfo.IF_ACCOUNT) && TextUtils.equals(sharedPreferences.getShareProf(UserInfo.IF_ACCOUNT), "YES")) {
                    if (sharedPreferences.getShareProf(UserInfo.OLD) != null) {
                        if (sharedPreferences.getShareProf(UserInfo.OLD).isEmpty() || MathUtils.compare(sharedPreferences.getShareProf(UserInfo.OLD), "18") < 0 || MathUtils.compare(sharedPreferences.getShareProf(UserInfo.OLD), "68") >= 0) {
                            showToast(getString(R.string.age_not_risk));
                            return;
                        }
                    }

                    zwgt_data = BaseRequestTool2.getFormatedDateString();
                    HashMap<String, String> hearder = BaseRequestTool2.getHearder(mContext, TaskConstants.TASK_GET, mContext.getString(R.string.h5_user) +
                            TaskConstants.TASK_RISKESTIMATE, sharedPreferences.getShareProf(UserInfo.USER_NO), sharedPreferences.getShareProf(UserInfo.TOKENID), zwgt_data);
                    HeaderMap headerMap = new HeaderMap();
                    headerMap.setMap(hearder);
                    Bundle bundle = new Bundle();
                    bundle.putString(BaseWebActivity.BUNDLE_KEY_TITLE, getString(R.string.risk_estimate));
                    bundle.putString(BaseWebActivity.BUNDLE_KEY_URL, getString(R.string.root_h5_url_test) + getString(R.string.h5_user) + TaskConstants.TASK_RISKESTIMATE);
                    bundle.putSerializable(BaseWebActivity.BUNDLE_KEY_HEADER, headerMap);
                    bundle.putInt(BaseWebActivity.BUNDLE_KEY_LOADTYPE, BaseWebActivity.LoadType.HTTP.getIntValue());
                    bundle.putBoolean(BaseWebActivity.BUNDLE_KEY_SHOW_BOTTOM_BAR, false);
                    readyGo(WebRiskActivity.class, bundle);
                } else {
                    //未开户
                    showToast(getString(R.string.open_account));
                    readyGo(OpenAccountBankActivity.class);
                }
                break;
            case R.id.ll_my_invest://我的投资
                if (TextUtils.equals(sharedPreferences.getShareProf(UserInfo.IF_ACCOUNT), "NO")) {
                    dialog_bindname = new HSDialog(getString(R.string.tips), getString(R.string.tips_openaccount),
                            getString(R.string.cancel), getString(R.string.tips_go_set), mContext,
                            this).setCancelable(false);//.setOnDismissListener(this);
                    dialog_bindname.show();
                } else {
                    readyGo(MineInvestActivity.class);
                }
                break;
            case R.id.ll_my_loan://我的借款
                if (TextUtils.equals(sharedPreferences.getShareProf(UserInfo.IF_ACCOUNT), "NO")) {
                    dialog_bindname = new HSDialog(getString(R.string.tips), getString(R.string.tips_openaccount),
                            getString(R.string.cancel), getString(R.string.tips_go_set), mContext,
                            this).setCancelable(false);//.setOnDismissListener(this);
                    dialog_bindname.show();
                } else {
                    readyGo(MineLoanActivity.class);
                }

                break;
            case R.id.ll_my_invest_stream://我的资金流水
                if (TextUtils.equals(sharedPreferences.getShareProf(UserInfo.IF_ACCOUNT), "NO")) {
                    dialog_bindname = new HSDialog(getString(R.string.tips), getString(R.string.tips_openaccount),
                            getString(R.string.cancel), getString(R.string.tips_go_set), mContext,
                            this).setCancelable(false);//.setOnDismissListener(this);
                    dialog_bindname.show();
                } else {
                    zwgt_data = BaseRequestTool2.getFormatedDateString();
                    HashMap<String, String> hearder6 = BaseRequestTool2.getHearder(mContext, TaskConstants.TASK_GET, mContext.getString(R.string.h5_user) +
                            TaskConstants.TASK_MYBANKBILL, sharedPreferences.getShareProf(UserInfo.USER_NO), sharedPreferences.getShareProf(UserInfo.TOKENID), zwgt_data);
                    HeaderMap headerMap6 = new HeaderMap();
                    headerMap6.setMap(hearder6);
                    Bundle bundle6 = new Bundle();
                    bundle6.putString(BaseWebActivity.BUNDLE_KEY_TITLE, getString(R.string.bank_record));
                    bundle6.putString(BaseWebActivity.BUNDLE_KEY_URL, getString(R.string.root_h5_url_test) + getString(R.string.h5_user) + TaskConstants.TASK_MYBANKBILL);
                    bundle6.putSerializable(BaseWebActivity.BUNDLE_KEY_HEADER, headerMap6);
                    bundle6.putInt(BaseWebActivity.BUNDLE_KEY_LOADTYPE, BaseWebActivity.LoadType.HTTP.getIntValue());
                    bundle6.putBoolean(BaseWebActivity.BUNDLE_KEY_SHOW_BOTTOM_BAR, false);
                    readyGo(WebActivity.class, bundle6);
                }
                break;
            case R.id.ll_contact_customer_service://联系客服
                consultService(mContext, null, null, null);
                break;
            case R.id.ll_help_center://帮助中心
                zwgt_data = BaseRequestTool2.getFormatedDateString();
                HashMap<String, String> hearder9 = BaseRequestTool2.getHearder(mContext, TaskConstants.TASK_GET, mContext.getString(R.string.h5_index) +
                        TaskConstants.TASK_HELPCENTE, "", mConfigSP.getShareProf(TaskConstants.TASK_CONFIG), zwgt_data);
                HeaderMap headerMap = new HeaderMap();
                headerMap.setMap(hearder9);
                Bundle bundle3 = new Bundle();
                bundle3.putString(BaseWebActivity.BUNDLE_KEY_TITLE, getString(R.string.more_help));
                bundle3.putString(BaseWebActivity.BUNDLE_KEY_URL, getString(R.string.root_h5_url_test) + getString(R.string.h5_index) + TaskConstants.TASK_HELPCENTE);
                bundle3.putSerializable(BaseWebActivity.BUNDLE_KEY_HEADER, headerMap);
                bundle3.putInt(BaseWebActivity.BUNDLE_KEY_LOADTYPE, BaseWebActivity.LoadType.HTTP.getIntValue());
                bundle3.putBoolean(BaseWebActivity.BUNDLE_KEY_SHOW_BOTTOM_BAR, false);
                readyGo(WebActivity.class, bundle3);
                break;
//            case R.id.ll_automatic_bid://自动投标
//                zwgt_data = BaseRequestTool2.getFormatedDateString();
//                mPresenter.loadingData(TaskConstants.TASK_AUTOBIDINFO, getString(R.string.root_url_test) + getString(R.string.api_user_test) + TaskConstants.TASK_AUTOBIDINFO, Constants.
//                        EVENT_REFRESH_DATA, new HashMap<String, String>(), BaseRequestTool2.getHearder(mContext, TaskConstants.TASK_GET, mContext.getString(R.string.api_user_test)
//                        + TaskConstants.TASK_AUTOBIDINFO, sharedPreferences.getShareProf(UserInfo.USER_NO), sharedPreferences.getShareProf(UserInfo.TOKENID), zwgt_data), true);
//                break;
            case R.id.ll_coupon://优惠券
                zwgt_data = BaseRequestTool2.getFormatedDateString();
                HashMap<String, String> hearder7 = BaseRequestTool2.getHearder(mContext, TaskConstants.TASK_GET, mContext.getString(R.string.h5_user) +
                        TaskConstants.TASK_MYDISCOUNT, sharedPreferences.getShareProf(UserInfo.USER_NO), sharedPreferences.getShareProf(UserInfo.TOKENID), zwgt_data);
                HeaderMap headerMap7 = new HeaderMap();
                headerMap7.setMap(hearder7);
                Bundle bundle7 = new Bundle();
                bundle7.putString(BaseWebActivity.BUNDLE_KEY_TITLE, getString(R.string.mine_bonus));
                bundle7.putString(BaseWebActivity.BUNDLE_KEY_URL, getString(R.string.root_h5_url_test) + getString(R.string.h5_user) + TaskConstants.TASK_MYDISCOUNT);
                bundle7.putSerializable(BaseWebActivity.BUNDLE_KEY_HEADER, headerMap7);
                bundle7.putInt(BaseWebActivity.BUNDLE_KEY_LOADTYPE, BaseWebActivity.LoadType.HTTP.getIntValue());
                bundle7.putBoolean(BaseWebActivity.BUNDLE_KEY_SHOW_BOTTOM_BAR, false);
                readyGo(WebActivity.class, bundle7);
                break;

            case R.id.ll_my_bank_card:
                readyGo(ManagementActivity.class);
                break;

            case R.id.ll_news_notice://新闻公告
                zwgt_data = BaseRequestTool2.getFormatedDateString();
                HashMap<String, String> hearder0 = BaseRequestTool2.getHearder(mContext, TaskConstants.TASK_GET, mContext.getString(R.string.h5_index) +
                        TaskConstants.TASK_NEWSLIST, "", mConfigSP.getShareProf(TaskConstants.TASK_CONFIG), zwgt_data);
                HeaderMap headerMap0 = new HeaderMap();
                headerMap0.setMap(hearder0);

                Bundle bundle0 = new Bundle();
                bundle0.putString(BaseWebActivity.BUNDLE_KEY_TITLE, getString(R.string.more_news));
                bundle0.putString(BaseWebActivity.BUNDLE_KEY_URL, getString(R.string.root_h5_url_test) + getString(R.string.h5_index) + TaskConstants.TASK_NEWSLIST);
                bundle0.putSerializable(BaseWebActivity.BUNDLE_KEY_HEADER, headerMap0);
                bundle0.putInt(BaseWebActivity.BUNDLE_KEY_LOADTYPE, BaseWebActivity.LoadType.HTTP.getIntValue());
                bundle0.putBoolean(BaseWebActivity.BUNDLE_KEY_SHOW_BOTTOM_BAR, false);
                readyGo(WebActivity.class, bundle0);
                break;

            case R.id.im_eye:
                if (assetInfoBean != null && bankAccountBeen != null && assetInfoBean.investAmount != null && !assetInfoBean.investAmount.isEmpty() && assetInfoBean.yesterdayIncome != null && !assetInfoBean.yesterdayIncome.isEmpty() && assetInfoBean.returnIncome != null && !assetInfoBean.returnIncome.isEmpty() && bankAccountBeen.depository_bank_no != null && !bankAccountBeen.depository_bank_no.isEmpty()) {
                    ISOPEN = !ISOPEN;
                    if (ISOPEN) {
                        im_eye.setImageResource(R.drawable.eye_on);
                        if (assetInfoBean != null && assetInfoBean.investAmount != null) {
                            tv_assets.setText(CommTool.keep2Digits(assetInfoBean.investAmount));
                        } else {
                            tv_assets.setText("---,---.--");
                        }

                        if (assetInfoBean != null && assetInfoBean.yesterdayIncome != null) {
                            tv_ear_from_yes_investment.setText(CommTool.keep2Digits(assetInfoBean.yesterdayIncome));
                        } else {
                            tv_ear_from_yes_investment.setText("0.00");
                        }

                        if (assetInfoBean != null && assetInfoBean.returnIncome != null) {
                            tv_cumulative_investment.setText(CommTool.keep2Digits(assetInfoBean.returnIncome));
                        } else {
                            tv_cumulative_investment.setText("0.00");
                        }

                        if (bankAccountBeen != null && bankAccountBeen.depository_bank_no != null) {
                            tv_cardnum.setText(bankAccountBeen.depository_bank_no);
                            tv_balance.setText(CommTool.keep2Digits(bankAccountBeen.availBal));
                        } else {
                            tv_cardnum.setText("----------------");
                            tv_balance.setText("0.00");
                        }
                    } else {
                        im_eye.setImageResource(R.drawable.eye_no);

                        double parseDouble = Double.parseDouble(assetInfoBean.investAmount);
                        tv_assets.setText(CommTool.encodNum((int) parseDouble + ""));
                        tv_ear_from_yes_investment.setText("**");
                        tv_cumulative_investment.setText("**");
                        tv_balance.setText("***");
                        tv_cardnum.setText(CommTool.encodBankNum(bankAccountBeen.depository_bank_no));
                    }
                }
                break;

            case R.id.ll_invite_frients://邀请好友
                readyGo(InviteFrientsActivity.class);
                break;

            case R.id.iv_user_logo://头像logo跳转设置页面
                readyGo(MineSettingActivity.class);
                break;
            case R.id.tv_assets:
                zwgt_data = BaseRequestTool2.getFormatedDateString();
                HashMap<String, String> hearder11 = BaseRequestTool2.getHearder(mContext, TaskConstants.TASK_GET, mContext.getString(R.string.h5_user) +
                        TaskConstants.TASK_ASSETINFO, sharedPreferences.getShareProf(UserInfo.USER_NO), sharedPreferences.getShareProf(UserInfo.TOKENID), zwgt_data);
                HeaderMap headerMap11 = new HeaderMap();
                headerMap11.setMap(hearder11);
                Bundle bundle11 = new Bundle();
                bundle11.putString(BaseWebActivity.BUNDLE_KEY_TITLE, getString(R.string.total_assets_unit_title));
//                bundle7.putString(WebProtocolActivity.PROTOCOL_CODE, EnumProtocol.findCode(EnumProtocol.HELP));
                bundle11.putString(BaseWebActivity.BUNDLE_KEY_URL, getString(R.string.root_h5_url_test) + getString(R.string.h5_user) + TaskConstants.TASK_ASSETINFO);
                bundle11.putSerializable(BaseWebActivity.BUNDLE_KEY_HEADER, headerMap11);
                bundle11.putInt(BaseWebActivity.BUNDLE_KEY_LOADTYPE, BaseWebActivity.LoadType.HTTP.getIntValue());
                bundle11.putBoolean(BaseWebActivity.BUNDLE_KEY_SHOW_BOTTOM_BAR, false);
                readyGo(WebActivity.class, bundle11);
                break;

            case R.id.ll_authorization:
//                readyGo(AuthorizationActivity.class);
                break;

        }
    }


    @Override
    public void onItemClick(Object o, int position) {
        // TODO Auto-generated method stub
        if ((HSDialog) o == dialog_bindcard) {
            if (position != -1) {
                if (TextUtils.equals(sharedPreferences.getShareProf(UserInfo.IF_PAYPWD), "YES")) {
                    readyGo(ManagementActivity.class);
                } else {
                    paypwdDialog = new HSDialog(getString(R.string.tips), getString(R.string.tips_nopaypwd),
                            getString(R.string.cancel), getString(R.string.tips_go_set), mContext, this).setCancelable(false);
                    paypwdDialog.show();
                }
            }
        } else if ((HSDialog) o == dialog_bindname) {
            if (position != -1) {
                readyGo(ManagementActivity.class);
            }
        } else if ((HSDialog) o == paypwdDialog) {
            if (position != -1) {
                readyGo(ManagementActivity.class);
            }
            //去实名认证
        } else if ((HSDialog) o == SignNameDialog && position != -1) {
            readyGo(ManagementActivity.class);
            //设置交易密码
        } else if ((HSDialog) o == payCodeDialog && position != -1) {
            readyGo(ManagementActivity.class);
            //立即绑卡
        } else if ((HSDialog) o == bindCardDialog && position != -1) {
            readyGo(ManagementActivity.class);
            //缴费授权
        } else if ((HSDialog) o == payDialog && position != -1) {
            readyGo(ManagementActivity.class);
        }
    }


    @Override
    public <T> void initializeViews(String task_name, T data) {
        mine_hsSwipeRefreshLayou.setRefreshing(false);

        if (TextUtils.equals(TaskConstants.TASK_BANK_ACCOUNT, task_name)) {
            //查询托管账户信息，更新ui
            bankAccountBeen = (BankAccountBeen) data;
            tv_balance.setText(CommTool.keep2Digits(bankAccountBeen.availBal));
            //对江西银行卡信息进行显示
            if (bankAccountBeen.depository_bank_no != null && !bankAccountBeen.depository_bank_no.isEmpty()) {//如果返回有银行卡信息，则将银行卡信息保存并且显示银行卡
                if (ISOPEN) {
                    tv_cardnum.setText(bankAccountBeen.depository_bank_no);
                } else {
                    tv_cardnum.setText(CommTool.encodBankNum(bankAccountBeen.depository_bank_no));
                }

                //将获得的银行卡信息保存
                sharedPreferences.putShareProf(UserInfo.JX_ACCOUNT_NO, bankAccountBeen.depository_bank_no);
            }

            //如果获取了用户的银行卡信息就将其绑定
            /**存储开户信息**/
            if (bankAccountBeen.depository_bank_no != null && !bankAccountBeen.depository_bank_no.isEmpty()) {
                sharedPreferences.putShareProf(UserInfo.JIANGXI_BANKCARD, bankAccountBeen.depository_bank_no);
                sharedPreferences.putShareProf(UserInfo.IF_ACCOUNT, "YES");
            } else {
                sharedPreferences.putShareProf(UserInfo.IF_ACCOUNT, "NO");
            }

            /**存储绑卡信息**/
            if (bankAccountBeen.bankCard != null && !bankAccountBeen.bankCard.isEmpty()) {
                sharedPreferences.putShareProf(UserInfo.BANKCARD, bankAccountBeen.bankCard);
                sharedPreferences.putShareProf(UserInfo.BANKCARDNAME, bankAccountBeen.bankName);

                sharedPreferences.putShareProf(UserInfo.IF_BINDCARD, "YES");
            } else {
                sharedPreferences.putShareProf(UserInfo.IF_BINDCARD, "NO");
            }

            if (bankAccountBeen.true_name != null && !bankAccountBeen.true_name.isEmpty()) {
                sharedPreferences.putShareProf(UserInfo.REAL_USER_NAME, bankAccountBeen.true_name);
            }

            /**
             * 绑定身份证
             */
            if (bankAccountBeen.cert_no != null && !bankAccountBeen.cert_no.isEmpty()) {
                sharedPreferences.putShareProf(UserInfo.CERT_NO, bankAccountBeen.cert_no);
            }

            /**保存登陆手机号**/
            //保存手机号码
            if (bankAccountBeen.phone != null && !bankAccountBeen.phone.isEmpty()) {
                sharedPreferences.putShareProf(UserInfo.MOBILE, bankAccountBeen.phone);
            }

            /**
             * 保存用户银行卡手机号
             */
            if (bankAccountBeen.depository_bank_mobile != null && !bankAccountBeen.depository_bank_mobile.isEmpty()) {
                sharedPreferences.putShareProf(UserInfo.BANKMOBILE, bankAccountBeen.depository_bank_mobile);
            } else {
                sharedPreferences.putShareProf(UserInfo.BANKMOBILE, "");
            }

            /*            *//**保存用户交易密码设置状态**/
            if (bankAccountBeen.set_paypwd_flag != null && !bankAccountBeen.set_paypwd_flag.isEmpty()) {
                if (TextUtils.equals(bankAccountBeen.set_paypwd_flag, "1")) {
                    //已经设置交易密码
                    sharedPreferences.putShareProf(UserInfo.IF_PAYPWD, "YES");
                } else {
                    sharedPreferences.putShareProf(UserInfo.IF_PAYPWD, "NO");
                }
            } else {
                sharedPreferences.putShareProf(UserInfo.IF_PAYPWD, "NO");
            }

            /**保存可用余额**/
            if (bankAccountBeen.availBal != null && !bankAccountBeen.availBal.isEmpty()) {
                sharedPreferences.putShareProf(UserInfo.CAN_USE_MONEY, bankAccountBeen.availBal);
            }

//            //保存用户vip等级
//            if (bankAccountBeen.vip != null && !bankAccountBeen.vip.isEmpty()) {
//                sharedPreferences.putShareProf(UserInfo.VIPLEVEL, bankAccountBeen.vip);
//                ll_automatic_bid.setVisibility(View.VISIBLE);
//            }

            closeProgress();
        } else if (TextUtils.equals(TaskConstants.TASK_ASSETINFO, task_name)) {
            assetInfoBean = (AssetInfoBean) data;

            sharedPreferences.putShareProf(UserInfo.FRIENT_TEXT, assetInfoBean.text);
            if (ISOPEN) {
                tv_assets.setText(CommTool.keep2Digits(assetInfoBean.investAmount));
                tv_ear_from_yes_investment.setText(CommTool.keep2Digits(assetInfoBean.yesterdayIncome));
                tv_cumulative_investment.setText(CommTool.keep2Digits(assetInfoBean.returnIncome));
            } else {
                double parseDouble = Double.parseDouble(assetInfoBean.investAmount);
                tv_assets.setText(CommTool.encodNum((int) parseDouble + ""));
                tv_ear_from_yes_investment.setText("**");
                tv_cumulative_investment.setText("**");
            }

        } else if (TextUtils.equals(TaskConstants.TASK_AUTOBIDINFO, task_name)) {
            AutoBidInfoBean autoBidInfoBean = (AutoBidInfoBean) data;
            Bundle bundle = new Bundle();
            bundle.putSerializable("autoBidAuthBean", autoBidInfoBean);
            readyGo(AutoBidAuthActivity.class, bundle);
        } else if (TextUtils.equals(TaskConstants.TASK_SETBANKPWD, task_name)) {
//
//            UpdatePayPwdBeen mUpdatePayPwdBeen = (UpdatePayPwdBeen) data;
//
//            //现在做另外一种操作
//            String postData = null;
//            try {
//                postData = "accountId=" + URLEncoder.encode(mUpdatePayPwdBeen.data.accountId.toString(), "utf-8") + "&acqRes=" + URLEncoder.encode(mUpdatePayPwdBeen.data.acqRes.toString(), "utf-8") +
//                        "&bankCode=" + URLEncoder.encode(mUpdatePayPwdBeen.data.bankCode.toString(), "utf-8") + "&channel=" + URLEncoder.encode(mUpdatePayPwdBeen.data.channel.toString(), "utf-8") +
//                        "&idNo=" + URLEncoder.encode(mUpdatePayPwdBeen.data.idNo.toString(), "utf-8") + "&idType=" + URLEncoder.encode(mUpdatePayPwdBeen.data.idType.toString(), "utf-8") + "&instCode=" +
//                        URLEncoder.encode(mUpdatePayPwdBeen.data.instCode.toString(), "utf-8") + "&lastSrvAuthCode=" + URLEncoder.encode(mUpdatePayPwdBeen.data.lastSrvAuthCode == null ? "" : mUpdatePayPwdBeen.data.lastSrvAuthCode.toString(), "utf-8") +
//                        "&mobile=" + URLEncoder.encode(mUpdatePayPwdBeen.data.mobile.toString(), "utf-8") + "&name=" + URLEncoder.encode(mUpdatePayPwdBeen.data.name.toString(), "utf-8") + "&notifyUrl=" +
//                        URLEncoder.encode(mUpdatePayPwdBeen.data.notifyUrl.toString(), "utf-8") + "&retUrl=" + URLEncoder.encode(mUpdatePayPwdBeen.data.retUrl.toString(), "utf-8") + "&seqNo=" +
//                        URLEncoder.encode(mUpdatePayPwdBeen.data.seqNo.toString(), "utf-8") + "&sign=" + URLEncoder.encode(mUpdatePayPwdBeen.data.sign.toString(), "utf-8") + "&smsCode=" +
//                        URLEncoder.encode(mUpdatePayPwdBeen.data.smsCode == null ? "" : mUpdatePayPwdBeen.data.smsCode.toString(), "utf-8") + "&txCode=" + URLEncoder.encode(mUpdatePayPwdBeen.data.txCode.toString(), "utf-8") +
//                        "&txDate=" + URLEncoder.encode(mUpdatePayPwdBeen.data.txDate.toString(), "utf-8") + "&txTime=" + URLEncoder.encode(mUpdatePayPwdBeen.data.txTime.toString(), "utf-8") + "&version=" +
//                        URLEncoder.encode(mUpdatePayPwdBeen.data.version.toString(), "utf-8");
//            } catch (UnsupportedEncodingException e) {
//                e.printStackTrace();
//            }
//
//            Bundle bundle1 = new Bundle();
//            bundle1.putString(BaseWebActivity.BUNDLE_KEY_TITLE, getString(R.string.set_paywd));
//            bundle1.putString(BaseWebActivity.BUNDLE_KEY_URL, mUpdatePayPwdBeen.url);
//            bundle1.putString(BaseWebActivity.BUNDLE_KEY_PARAMS, postData);
//            bundle1.putInt(BaseWebActivity.BUNDLE_KEY_LOADTYPE, BaseWebActivity.LoadType.POSTDATA.getIntValue());
//            bundle1.putBoolean(BaseWebActivity.BUNDLE_KEY_SHOW_BOTTOM_BAR, false);
//            readyGo(WebSetPasswordActivity.class, bundle1);
            if (data == null) {
                return;
            }
            zwgt_data = BaseRequestTool2.getFormatedDateString();
            HashMap<String, String> hearder = BaseRequestTool2.getHearder(mContext, TaskConstants.TASK_GET, mContext.getString(R.string.h5_user) +
                    TaskConstants.TASK_SETBANKPWD, sharedPreferences.getShareProf(UserInfo.USER_NO), sharedPreferences.getShareProf(UserInfo.TOKENID), zwgt_data);
            HeaderMap headerMap2 = new HeaderMap();
            headerMap2.setMap(hearder);
            Bundle bundler = new Bundle();
            bundler.putString(BaseWebActivity.BUNDLE_KEY_URL, data.toString());
            bundler.putSerializable(BaseWebActivity.BUNDLE_KEY_HEADER, headerMap2);
            bundler.putInt(BaseWebActivity.BUNDLE_KEY_LOADTYPE, BaseWebActivity.LoadType.DATA.getIntValue());
            readyGo(WebOpenAccountActivity.class, bundler);

            /**
             * 提现操作判断
             */
        } else if (TextUtils.equals(TaskConstants.TASK_NEW_TRADE, task_name)) {
            AdSlideBeen adSlideBeen = (AdSlideBeen) data;
            switch (((AdSlideBeen) data).getCode()) {
                case "000001":
                    SignNameDialog = new HSDialog(getString(R.string.tips), adSlideBeen.getMsg(),
                            "暂不实名", "立即实名", mContext,
                            this).setCancelable(false);//.setOnDismissListener(this);
                    SignNameDialog.show();
                    break;
                case "000002":
                    payCodeDialog = new HSDialog(getString(R.string.tips), adSlideBeen.getMsg(), "暂不设置", "立即设置", mContext,
                            this).setCancelable(false);
                    payCodeDialog.show();
                    break;
                case "000003":
                    //未绑卡，跳转至绑卡
                    bindCardDialog = new HSDialog(getString(R.string.tips), adSlideBeen.getMsg(), "暂不绑卡", "立即绑卡", mContext,
                            this).setCancelable(false);
                    bindCardDialog.show();
                    break;
                case "000004":
                    payDialog = new HSDialog(getString(R.string.tips), adSlideBeen.getMsg(), "暂不签约", "立即签约", mContext,
                            this).setCancelable(false);
                    payDialog.show();
                    break;
            }
        } else if (TextUtils.equals(TaskConstants.TASK_IDCARD, task_name)) {
            MixrepayPlanBean mixrepayPlanBean = (MixrepayPlanBean) data;
            switch (((MixrepayPlanBean) data).getIs_lender()) {
                //出借用户
                case "1":
                    readyGo(WithDrawActivity.class);
                    break;
                //借款人
                case "2":
                    readyGo(LendActivity.class);
                    break;
                //担保人
                case "3":
                    readyGo(WithDrawActivity.class);
                    break;
            }
        }
    }

    @Override
    public <T> void initializeError(String task_name, T data) {
        mine_hsSwipeRefreshLayou.setRefreshing(false);
        if (TextUtils.equals(TaskConstants.TASK_BANK_ACCOUNT, task_name)) {
            assetResult = "";
            if (sharedPreferences.getBoolean(UserInfo.ISLOGIN)) {
            } else {
            }

            try {
            } catch (IllegalStateException e) {
                e.printStackTrace();
            }
        }
    }

    @SuppressWarnings("unchecked")
    @Override
    public <T> void setAdapter(List<T> data) {
        ViewCreatorHelper<HashMap<String, Object>> creatorHelper = new ViewCreatorHelper<HashMap<String, Object>>(R.layout.item_mine, this);
        mAdapter = new HolderAdapter<HashMap<String, Object>>(mContext, creatorHelper.viewCreator());

//        gv_mine.setAdapter(mAdapter);
        mAdapter.update((List<HashMap<String, Object>>) data);
    }


    private void consultService(final Context context, String uri, String title, ProductDetail productDetail) {
        if (!Unicorn.isServiceAvailable()) {
            // 当前客服服务不可用
            AlertDialog.Builder dialog = new AlertDialog.Builder(context);
            if (!Utils.isNetworkAvailable(context)) {
                // 当前无网络
                dialog.setMessage("网络状况不佳，请重试。");
                dialog.setPositiveButton("确定", null);
                dialog.show();
            }
            return;
        }
        try {
            long when = System.currentTimeMillis();
            TimeZone.setDefault(TimeZone.getTimeZone("GMT+8"));
        } catch (Exception e) {

        }

        if (sharedPreferences.getShareProf("before_user_no") != null && !sharedPreferences.getShareProf("before_user_no").equals(sharedPreferences.getShareProf(UserInfo.USER_NO))) {
            Unicorn.setUserInfo(null);
        }

        // 启动聊天界面
        ConsultSource source = new ConsultSource(uri, title, null);

        SimpleDateFormat df = new SimpleDateFormat();
        df.setTimeZone(TimeZone.getTimeZone("GMT+8"));
        Calendar.getInstance().setTimeZone(TimeZone.getTimeZone("GMT+8"));

        source.productDetail = productDetail;
        YSFUserInfo userInfo = new YSFUserInfo();
        userInfo.userId = sharedPreferences.getShareProf(UserInfo.USER_NO);
        userInfo.data = "[{\"key\":\"real_name\", \"value\":" + sharedPreferences.getShareProf(UserInfo.REALNAME) + "},{\"key\":\"mobile_phone\", \"hidden\":false}]";
        sharedPreferences.putShareProf("before_user_no", userInfo.userId);
        Unicorn.setUserInfo(userInfo);
        Unicorn.openServiceActivity(context, "中网国投客服", source);
    }

    /**
     * 防止按钮连续点击
     */
    private static long lastClickTime;

    public static boolean isFastDoubleClick() {
        long time = System.currentTimeMillis();
        if (time - lastClickTime < 500) {
            return true;
        }
        lastClickTime = time;
        return false;
    }

    public boolean onKeyDown(int keyCode, KeyEvent event) {
        // TODO Auto-generated method stub
        if (keyCode == event.KEYCODE_BACK) {
            if (dialog_bindcard != null && dialog_bindcard.isShowing()) {
                dialog_bindcard.dismiss();
                return true;
            } else if (dialog_bindname != null && dialog_bindname.isShowing()) {
                dialog_bindname.dismiss();
                return true;
            } else {
                return false;
            }
        }
        return false;
    }


    @Override
    public void onRefresh() {
        zwgt_data = BaseRequestTool2.getFormatedDateString();
        mPresenter.loadingData(TaskConstants.TASK_BANK_ACCOUNT, getString(R.string.root_url_test) + getString(R.string.api_user_test) +
                TaskConstants.TASK_BANK_ACCOUNT, Constants.EVENT_BEGIN, BaseRequestTool2.getHearder(mContext, TaskConstants.TASK_GET, getString(R.string.api_user_test)
                + TaskConstants.TASK_BANK_ACCOUNT, sharedPreferences.getShareProf(UserInfo.USER_NO), sharedPreferences.getShareProf(UserInfo.TOKENID), zwgt_data), false);

        zwgt_data = BaseRequestTool2.getFormatedDateString();
        mPresenter.loadingData(TaskConstants.TASK_ASSETINFO, getString(R.string.root_url_test) + getString(R.string.api_user_test) +
                TaskConstants.TASK_ASSETINFO, Constants.EVENT_BEGIN, BaseRequestTool2.getHearder(mContext, TaskConstants.TASK_GET, getString(R.string.api_user_test)
                + TaskConstants.TASK_ASSETINFO, sharedPreferences.getShareProf(UserInfo.USER_NO), sharedPreferences.getShareProf(UserInfo.TOKENID), zwgt_data), false);
    }


    /**
     * 展示popupwindow
     *
     * @param parent
     */
    private void showPopup(View parent, boolean isopenaccount) {
        backgroundAlpha((float) 0.3);
        View view = null;

        LayoutInflater layoutInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = layoutInflater.inflate(R.layout.pop_open_account, null);

        popWindow = new PopupWindow(view, LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.MATCH_PARENT, true);

        ImageView iv_close_pop = findView(view, R.id.iv_close_pop);
        iv_close_pop.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                popWindow.dismiss();
            }
        });
        ImageView iv_back_pop = findView(view, R.id.iv_back_pop);
        HSButton btn_go_to_openaccount = findView(view, R.id.btn_go_to_openaccount);

        if (isopenaccount) {
            iv_back_pop.setImageResource(R.drawable.back_register_success);
            btn_go_to_openaccount.setText(getString(R.string.certification));
            btn_go_to_openaccount.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    ISNEWREGISTER = true;
                    readyGo(OpenAccountBankActivity.class);
                }
            });

            popWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
                @Override
                public void onDismiss() {
                    ISNEWREGISTER = false;
                }
            });
        } else {
            iv_back_pop.setImageResource(R.drawable.back_account_success);
            btn_go_to_openaccount.setText(getString(R.string.go_to_invest));
            btn_go_to_openaccount.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    NoScrollViewPager noScrollViewPager = (NoScrollViewPager) ((MainActivity) getActivity()).findViewById(R.id.viewpager);
                    noScrollViewPager.setCurrentItem(1);
                    popWindow.dismiss();
                }
            });
        }

        // 设置背景，这个是为了点击“返回Back”也能使其消失，并且并不会影响你的背景
        popWindow.setBackgroundDrawable(getResources().getDrawable(R.color.transparent_66));
        ColorDrawable cd = new ColorDrawable(Color.TRANSPARENT);
        popWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        //popupwindow弹出时的动画
//        popWindow.setAnimationStyle(R.style.project_pop_style);
        popWindow.setClippingEnabled(false);
        //软键盘不会挡着popupwindow
        popWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
        //监听菜单的关闭事件
        popWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                backgroundAlpha(1f);
            }
        });

        popWindow.setTouchable(true);
        // 使其聚集 ，要想监听菜单里控件的事件就必须要调用此方法
        popWindow.setFocusable(true);
        // 设置允许在外点击消失
        popWindow.setOutsideTouchable(true);
//        //监听触屏事件
        popWindow.setTouchInterceptor(new View.OnTouchListener() {
            @SuppressLint("ClickableViewAccessibility")
            public boolean onTouch(View view, MotionEvent event) {
                return false;
            }
        });
        popWindow.showAtLocation(parent, Gravity.CENTER, 0, 0);
    }

    /**
     * 设置添加屏幕的背景透明度
     *
     * @param bgAlpha
     */
    public void backgroundAlpha(float bgAlpha) {
        WindowManager.LayoutParams lp = getActivity().getWindow().getAttributes();
        lp.alpha = bgAlpha; //0.0-1.0
        getActivity().getWindow().setAttributes(lp);
    }
}
